home *** CD-ROM | disk | FTP | other *** search
- Path: news.telepac.pt!usenet
- From: a.leote@mail.telepac.pt (Carlos Leote)
- Newsgroups: comp.lang.c
- Subject: Why this DOS4GW CD identifier doesn┤t work
- Date: Wed, 03 Jan 1996 23:36:51 GMT
- Organization: telepac
- Message-ID: <4ccive$p4q@vivaldi.telepac.pt>
- NNTP-Posting-Host: ptm1_p1.telepac.pt
- X-Newsreader: Forte Free Agent 1.0.82
-
- Please,anybody could tell me what's wrong with this code?
- I'm trying to get CD ROM info calling MSCDEX services in
- Protected Mode with Watcom Dos4gw.
- I'm calling a Real Mode Interrupt like the book teatches
- but all i'll get so far it was tons of crashes.
- Many thanks in Advance.
- Carlos Leote
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <conio.h>
- #include <dos.h>
- #include "defines.h"
-
- extern int DPMI_allocRealSeg(int size,int *sel,int *r_seg);
- extern void DPMI_freeRealSeg(dword selector);
- extern void * DPMI_getSelectorBase(int sel);
- extern long DPMI_simRealInt(dword int_number,void *adress);
-
- typedef struct{ unsigned char length;
- unsigned char subunit;
- unsigned char comcode;
- unsigned short status;
- char ununsed[8];
- unsigned char media;
- long address;
- short bytes;
- short sector;
- long volid; } s_ioctli;
- typedef struct {unsigned char mode;
- unsigned char lowest;
- unsigned char highest;
- unsigned long address; } s_track_data;
- struct s_cdrom_data{ unsigned short drives;
- unsigned char first_drive;
- unsigned short current_track;
- unsigned long track_position;
- unsigned char track_type;
- unsigned char low_audio;
- unsigned char high_audio;
- unsigned char disk_length_min;
- unsigned char disk_length_sec;
- unsigned char disk_length_frames;
- unsigned long endofdisk;
- unsigned char upc[7];
- unsigned char diskid[6];
- unsigned long status;
- unsigned short error; } cdrom_data;
- struct s_rmi{ long edi;
- long esi;
- long ebp;
- long reserved;
- long ebx;
- long edx;
- long ecx;
- long eax;
- short flags;
- short es,ds,fs,gs,ip,cs,sp,ss; } RMI;
-
- int Buf_len=1024;
- int Buf_sel=0;
- int Buf_rseg;
-
- union REGS regs;
- struct SREGS sregs;
-
- main()
- {
- s_ioctli *ioctli;
- s_track_data *track_data;
- dword ciclo;
- byte *real_pointer;
-
- regs.h.ah = 0x15;
- regs.h.al = 0x00;
- regs.w.bx = 0;
- int386 (0x2f, ®s, ®s);
- if (regs.w.bx == 0) return (0); // Return if no CDROM
- cdrom_data.drives = regs.w.bx;
- cdrom_data.first_drive = regs.w.cx;
-
- DPMI_allocRealSeg(Buf_len,&Buf_sel,&Buf_rseg); //Allocate real
- memory
- real_pointer=DPMI_getSelectorBase(Buf_sel); //linear Pointer to
- real memory
- ioctli=(s_ioctli *)real_pointer;
- track_data=(s_track_data *)(real_pointer+30);
-
- _fmemset(real_pointer,0,50); // set [real memory]=0
- ioctli->length = sizeof (s_ioctli);
- ioctli->comcode = 3;
- ioctli->address = 30;
- ioctli->bytes = sizeof (s_track_data);
- track_data->mode = 0x0a;
-
- RMI.eax=0x00001510;
- RMI.ecx=cdrom_data.first_drive;
- RMI.es=Buf_rseg;
- RMI.edi=0;
- DPMI_simRealInt(0x2f,&RMI); // Real mode interrupt
-
- DPMI_freeRealSeg(Buf_sel);
- }
-
- .386p
- .MODEL FLAT
- NOJUMPS
-
- DATA SEGMENT PUBLIC USE32 'DATA'
- ASSUME DS:DATA
-
- DATA ENDS
-
- CODE SEGMENT PUBLIC USE32 'CODE'
- ASSUME CS:CODE
-
- PUBLIC DPMI_allocRealSeg
- PUBLIC DPMI_freeRealSeg
- PUBLIC DPMI_getSelectorBase
- PUBLIC DPMI_simRealInt
-
- ; Function: DPMI_allocRealSeg
- DPMI_allocRealSeg PROC NEAR
- ARG amount:DWORD,selector:DWORD,r_segment:DWORD
- push ebp
- mov ebp,esp
- push ebx
-
- xor edx,edx
- mov ebx,amount ; Get number of bytes requested.
- add bx,0fh ; Round up to closest number of
- paragraphs.
- shr ebx,4 ;/16.
- mov eax,100h ; Interrupt number.
- int 31h ; Allocate memory.
-
- jc _ERR
- mov ebx,[selector] ; Get address of selector.
- mov [ebx],dx ; Save selector.
- mov ebx,[r_segment] ; Get address of selector.
- mov [ebx],ax ; Save selector.
- jmp short _RET
- _ERR: xor eax,eax ; Zero return address.
-
- _RET: pop ebx
- pop ebp
- ret
- DPMI_allocRealSeg ENDP
-
- ; Function: DPMI_freeRealSeg
-
- DPMI_freeRealSeg PROC NEAR
- ARG selector:DWORD
- push ebp
- mov ebp,esp
- push ebx
-
- mov edx,selector
- mov eax,101h
- int 31h
-
- pop ebx
- pop ebp
- ret
- DPMI_freeRealSeg ENDP
-
- ; Function: DPMI_getSelectorBase
-
- DPMI_getSelectorBase PROC NEAR
- ARG selector:DWORD
- push ebp
- mov ebp,esp
- push ebx
-
- mov eax,6
- mov ebx,selector
- int 31h
- jc _ERR6
- mov eax,ecx
- shl eax,16
- mov ax,dx
- jmp short _RET6
- _ERR6: xor eax,eax ; Zero return address.
-
- _RET6: pop ebx
- pop ebp
- ret
- DPMI_getSelectorBase ENDP
-
- ; Function: DPMI_simRealInt
-
- DPMI_simRealInt PROC NEAR
- ARG interrupt:DWORD,adress:DWORD
- push ebp
- mov ebp,esp
- push ebx
- push es
-
- mov ebx,interrupt ;put the interrupt in bl
- mov edi,adress ;put the address of dataStruct in
- edi
- mov eax,00000300h
- mov ecx,0
- int 31h
- jc _ERR5 ;if the carry flag is set we have a
- failure
- mov eax,1
- jmp short _RET5
- _ERR5: xor eax,eax ; Zero return address.
-
- _RET5: pop es
- pop ebx
- pop ebp
- ret
- DPMI_simRealInt ENDP
-
- CODE ENDS
- END
-
-
-
-